Skip to content

feat(js): added dynamicTool factory function that does not depend on genkit instance #3026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 10, 2025

Conversation

pavelgj
Copy link
Collaborator

@pavelgj pavelgj commented Jun 4, 2025

import { dynamicTool } from 'genkit';

const dynamicGablorkenTool = dynamicTool(
  {
    name: 'dynamicGablorkenTool',
    inputSchema: z.object({
      value: z.number(),
    }),
    description: 'can be used to calculate gablorken value',
  },
  async (input) => {
    return input.value * 3 - 4;
  }
);

const { text } = ai.generateStream({
  model: googleAI.model('gemini-2.0-flash'),
  tools: [dynamicGablorkenTool],
  prompt: `what is a gablorken of ${input}`,
});

also added global (Genkit instance level) context:

const ai = genkit({
  context: { something: 'extra' }
});

Checklist (if applicable):

@pavelgj pavelgj requested a review from mbleigh June 4, 2025 02:05
@pavelgj pavelgj marked this pull request as ready for review June 4, 2025 20:33
Modify the generate test to include a non-serializable object in the context. This ensures that the serialization logic handles such cases correctly.
@pavelgj pavelgj requested a review from ifielker June 5, 2025 14:14
@pavelgj pavelgj enabled auto-merge (squash) June 10, 2025 15:43
@pavelgj pavelgj merged commit 8fe3719 into main Jun 10, 2025
5 checks passed
@pavelgj pavelgj deleted the pj/js-unregistered-tools branch June 10, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants